package com.xbts.system.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;


import com.xbts.system.domain.CnSolution;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 数据盘Mapper接口
 *
 * @author xbts
 * @date 2023-08-07
 */
public interface CnSolutionMapper extends BaseMapper<CnSolution> {

    // 每个解决方案的内容只查询一条出来
    @Select("SELECT solution_id,solution_name,ancestors,parent_id,content,create_by,create_time,update_by,update_time,sort,remark,img_url \n" +
            "FROM cn_solution t \n" +
            "where (LENGTH(ancestors) - LENGTH(REPLACE(ancestors, ',', ''))  = 1 or parent_id = 0)\n" +
            "union \n" +
            "SELECT solution_id,solution_name,ancestors,parent_id,content,create_by,create_time,update_by,update_time,sort,remark,img_url \n" +
            "FROM ( SELECT solution_id,solution_name,ancestors,parent_id,content,create_by,create_time,update_by,update_time,sort,remark,img_url  FROM cn_solution ORDER BY sort,create_time LIMIT 10000  ) a \n" +
            "where LENGTH(ancestors) - LENGTH(REPLACE(ancestors, ',', ''))  = 2\n" +
            "GROUP BY parent_id")
    List<CnSolution> getList();

    @Select("SELECT solution_id,solution_name,ancestors,parent_id,content,create_by,create_time,update_by,update_time,sort,remark,img_url \n" +
            "FROM cn_solution t \n" +
            "where (LENGTH(ancestors) - LENGTH(REPLACE(ancestors, ',', ''))  = 1 or parent_id = 0)\n")
    List<CnSolution> getTypeList();
}
